package com.huibo.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Set;

@Component
@EnableScheduling
public class ScheduleRun {

    @Autowired
    private StringRedisTemplate redisTemplate;


    /**
     * 每28天清理redis数据库
     * 这样用户查询的时候因为数据库没东西所以会调用算法重新生成
     */
    @Scheduled(cron = "0 0 0 */28 * ?")
    public void function() {
        Set<String> keys = redisTemplate.keys("*" +"_"+ "*");
        redisTemplate.delete(keys);
    }
}

